I'm working with DOORS 8.2, and I see that the find/replace does not incorporate formatting. |
Re: Find/Replace with formatting |
Re: Find/Replace with formatting SystemAdmin - Fri Sep 17 15:32:24 EDT 2010 It has become a helpful convention here to bold the words "shall" and "should" in the text, but apparently they were not bolded in the source document we imported. This seems like a pretty straightforward thing to do, but I'm still a novice. |
Re: Find/Replace with formatting Module m = current Object o string bodyText string shall = "shall" string should = "should" string boldShall = "{\\b shall}" string boldShould = "{\\b should}" int offset int len for o in m do { bodyText = o."Object Text" print bodyText "\n" if (findRichText(bodyText, should, offset, len, false)) { bodyText = replaceRichText(bodyText, offset, len, boldShould) } if (findRichText(bodyText, shall, offset, len, false)) { bodyText = replaceRichText(bodyText, offset, len, boldShall) } o."Object Text" = bodyText } But I'm clearly not manipulating the rich text correctly... Before: This shall be my example. After: This \{\\b shall\} be my example. How can I keep those extra escape characters from being inserted? |
Re: Find/Replace with formatting meldobbs - Mon Sep 20 12:14:07 EDT 2010
I think replaceRichText will retain the formatting therefore escaping all richtext markup in your string, therefore you cannot use that. What you could do is something like this:
Module m = current
Object o = current
// set the object text to something that already contains richText so we are sure we retain formatting
o."Object Text" = richText "We sh{\\b a}ll da{\\b nc}e!"
// read the richText
Buffer bodyText = create()
bodyText = richTextWithOle o."Object Text"
Buffer newText = create()
int len, offset
if (findRichText(tempStringOf bodyText, "shall", offset, len, false) && offset > 0)
{
// manually replace the richText
combine (newText, bodyText, 0, offset-1)
newText += "{\\b shall}"
combine (newText, bodyText, offset+len)
}
o."Object Text" = richText tempStringOf newText
delete newText
delete bodyText
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Find/Replace with formatting Mathias Mamsch - Tue Sep 21 03:13:47 EDT 2010
I think replaceRichText will retain the formatting therefore escaping all richtext markup in your string, therefore you cannot use that. What you could do is something like this:
Module m = current
Object o = current
// set the object text to something that already contains richText so we are sure we retain formatting
o."Object Text" = richText "We sh{\\b a}ll da{\\b nc}e!"
// read the richText
Buffer bodyText = create()
bodyText = richTextWithOle o."Object Text"
Buffer newText = create()
int len, offset
if (findRichText(tempStringOf bodyText, "shall", offset, len, false) && offset > 0)
{
// manually replace the richText
combine (newText, bodyText, 0, offset-1)
newText += "{\\b shall}"
combine (newText, bodyText, offset+len)
}
o."Object Text" = richText tempStringOf newText
delete newText
delete bodyText
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
Thanks so much for the help. I modified your code a bit to allow for looping through the entire module and to catch instances of multiple shalls in a single object. Here's what I ended up with: Module m = current Object o Buffer bodyText = create() Buffer newText = create() int len, offset for o in m do { newText = "" bodyText = richTextWithOle o."Object Text" while (findRichText(tempStringOf bodyText, "shall", offset, len, false) && offset > 0) { combine (newText, bodyText, 0, offset-1) newText += "{\\b shall}" //combine (newText, bodyText, offset+len) bodyText = bodyTextoffset+len: } combine (newText, bodyText, 0) o."Object Text" = richText tempStringOf newText } delete newText delete bodyText Seems to work like a charm. Thanks again! |
Re: Find/Replace with formatting meldobbs - Wed Sep 29 10:27:38 EDT 2010
Here it is again with proper formatting ...
Module m = current
Object o
Buffer bodyText = create()
Buffer newText = create()
int len, offset
for o in m do
{
newText = ""
bodyText = richTextWithOle o."Object Text"
while (findRichText(tempStringOf bodyText, "shall", offset, len, false) && offset > 0)
{
combine (newText, bodyText, 0, offset-1)
newText += "{\\b shall}"
//combine (newText, bodyText, offset+len)
bodyText = bodyText[offset+len:]
}
combine (newText, bodyText, 0)
o."Object Text" = richText tempStringOf newText
}
delete newText
delete bodyText
|
Re: Find/Replace with formatting meldobbs - Wed Sep 29 10:34:22 EDT 2010
Here it is again with proper formatting ...
Module m = current
Object o
Buffer bodyText = create()
Buffer newText = create()
int len, offset
for o in m do
{
newText = ""
bodyText = richTextWithOle o."Object Text"
while (findRichText(tempStringOf bodyText, "shall", offset, len, false) && offset > 0)
{
combine (newText, bodyText, 0, offset-1)
newText += "{\\b shall}"
//combine (newText, bodyText, offset+len)
bodyText = bodyText[offset+len:]
}
combine (newText, bodyText, 0)
o."Object Text" = richText tempStringOf newText
}
delete newText
delete bodyText
Try your code with these texts Text Bold? Result The pond is too shallow. Yes The pond is too SHALLow. The system Shall do stuff. No The system Shall do stuff. The system shall do shallshall stuff. 2 of 3 The system SHALL do SHALLshall stuff. shall do it. No shall do it.
|
Re: Find/Replace with formatting llandale - Wed Sep 29 11:51:41 EDT 2010 Try your code with these texts Text Bold? Result The pond is too shallow. Yes The pond is too SHALLow. The system Shall do stuff. No The system Shall do stuff. The system shall do shallshall stuff. 2 of 3 The system SHALL do SHALLshall stuff. shall do it. No shall do it.
@Louie: You are right, this is indeed more complicated. What I did not get is that findRichText did not catch the uppercase/lowercase stuff, since the 'matchcase' bool parameter is set to false. In my tests this works fine. ... bodyText = bodyText[offset+len:] // never do this with a buffer, when you manipulate large strings!! // Since buffer[x:y] can also a buffer OR a string you may just throw away the old buffer // without deleting it and assign a (newly created) buffer that contains the range of the old buffer. // Always do like this: // // Buffer temp = create(); combine(temp, bodyText, offset+len); // delete bodyText; bodyText = temp //
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Find/Replace with formatting meldobbs - Wed Sep 29 10:34:22 EDT 2010
Here it is again with proper formatting ...
Module m = current
Object o
Buffer bodyText = create()
Buffer newText = create()
int len, offset
for o in m do
{
newText = ""
bodyText = richTextWithOle o."Object Text"
while (findRichText(tempStringOf bodyText, "shall", offset, len, false) && offset > 0)
{
combine (newText, bodyText, 0, offset-1)
newText += "{\\b shall}"
//combine (newText, bodyText, offset+len)
bodyText = bodyText[offset+len:]
}
combine (newText, bodyText, 0)
o."Object Text" = richText tempStringOf newText
}
delete newText
delete bodyText
Thanks! |